

const fs = require('fs');

var outFunctions;



//手写输入系统
outFunctions = function(){

	
	function fileCoverValAtPosInner(filePath,contentToWrite,position){
	
		return new Promise(function(resolve,reject){
			
			
			// 打开文件
			fs.open(filePath, 'r+', (err, fd) => {
			  if (err) {
				if (err.code === 'ENOENT') {
					reject("文件不存在");
				  return;
				}
				throw err;
			  }
			 
			  // 写入内容
			  fs.write(fd, contentToWrite, 0, contentToWrite.length, position, (writeErr) => {
				if (writeErr){
					reject(writeErr);
				};
				//console.log('内容已覆盖');
				resolve(true);
				fs.close(fd, (closeErr) => {
				  if (closeErr){
					reject(closeErr);
				  };
				});
			  });
			});
			
			
		});
	
	
		
 
 
	}
	
	return{
	  fileCoverValAtPosInner:fileCoverValAtPosInner,
	}
}();

	
if(typeof module != "undefined"){
	//模块导出
	module.exports = outFunctions
}


